package cn.tedu.servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.tedu.entity.User;
import cn.tedu.service.UserService;
import cn.tedu.service.impl.UserServiceImpl;
import cn.tedu.util.CommonValue;

/**
 * Servlet implementation class UserShowAllServlet
 */
public class UserShowAllServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public UserShowAllServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		//1.获取提交过来的数据(无)
	
		//2.调用查询所有用户信息的业务
		UserService userService=new UserServiceImpl();
		List<User> users=userService.findAllUsers();
		System.out.println("UserShowAllServlet-->"+users);
		
		
		//3.根据业务返回的结果做跳转/响应工作
		//把查询出来的List集合中的数据   "转发"   usershowall.jsp
		//a.要绑定数据给request对象
		request.setAttribute("suoyouyonghu", users);
		//b.把已经绑定数据的request对象转发到usershowall.jsp中
		//request.getRequestDispatcher("usershowall.jsp").forward(request, response);
		RequestDispatcher rd=request.getRequestDispatcher("usershowall.jsp");
		rd.forward(request, response);
		System.out.println("UserShowAllServlet.doGet方法执行完毕");
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
